import 'package:amway_superapp_creator_plugin/models/circle_detail_model.dart';
import 'package:amway_superapp_creator_plugin/net/http_manager.dart';
import 'package:flutter/cupertino.dart';

import '../../api.dart';
import '../../view_state.dart';
import '../base_model.dart';


class MyCircleDetailsModel extends BaseModel {
  MyCircleDetailsModel({@required Api api}) : super(api: api);
  int _curIndex = 1;

  int get curIndex => _curIndex;

  set curIndex(int value) {
    _curIndex = value;
    notifyListeners();
  }

  CircleDetailData circleDetail;

  void getCircleDetail(String id) {
    setState(ViewState.Busy);
    HttpManager().get(
        url: "apis/v1/creator/circles/$id",
        tag: null,
        successCallback: (data) {
          setState(ViewState.Idle);
          if (data != null) {
            circleDetail = CircleDetailData.fromJson(data);
          }
        },
        errorCallback: (data) {
          setState(ViewState.Idle);
        });
  }

/*
* 发布
* */
  void release(String id, {BoolStringCallBack back}) {
    HttpManager().put(
        url: "apis/v1/creator/circles/$id/publish/",
        tag: null,
        successCallback: (data) {
          back.call(true, "");
        },
        errorCallback: (data) {
          back.call(false, data.message);
        });
  }

  void revokeRelease(String id, {BoolCallBack back}) {
    HttpManager().put(
        url: "apis/v1/creator/circles/$id/un_publish/",
        tag: null,
        successCallback: (data) {
          if (data != null) {
            getCircleDetail(id);
            back.call(true);
          }
        },
        errorCallback: (data) {
          back.call(false);
        });
  }
}
